﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ListsForm
{
    public partial class FrmChangePassword : BasicForms.FrmBase
    {
        Lists.Account _Account;
        public FrmChangePassword(Lists.Account account)
        {
            InitializeComponent();
            _Account = account;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtPassword.Text.Trim()))
                    throw new Exception("Enter new password!");
                if(string.IsNullOrEmpty(txtRePassword.Text.Trim()))
                    throw new Exception("Retyping password!");
                if (!txtRePassword.Text.Equals(txtPassword.Text))
                    throw new Exception("Password not match. Please retyping password!");
                bool result = _Account.ChangePassword(GeneralLibs.CommonLib.MaHoaMD5(txtPassword.Text.Trim()));
                if (result)
                {
                    MessageBox.Show("Change password successfully!");
                }
                else
                {
                    MessageBox.Show("Change password failure!");
                }
                this.Close();
            }
            catch (Exception ex)
            {
                BasicForms.FrmWarning.Show(ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmChangePassword_Load(object sender, EventArgs e)
        {
            txtUserName.Text = _Account.AccountName;
        }
    }
}
